function Path(url, option = {
    isConsoleLog: true,
    preFix: 'URL'
}) {
    this.url = url;
    this.option = option;
}

Path.prototype = {
    constructor: Path,
    addQuery(param = {}) {
        // 是否有问号
        let hasMark = this.url.indexOf('?') > 0;
        let preFix = hasMark ? '&' : '?';
        let result = this.url;

        Object.keys(param).map((key, index) => {
            if (index === 0) {
                result += `${preFix}${key}=${param[key]}`;
            } else {
                result += `&${key}=${param[key]}`;
            }
        })
        return result;
    },
    getQuery(key) {

        let search = this.url.replace(/.*?\?/, "");

        // let queryArr = document.location.search.slice(1).split("&");
        let queryArr = search.split("&");

        this.printInfo("queryArr==>", queryArr);
        let result = "";
        if (queryArr.length) {
            for (let i = 0; i < queryArr.length; i++) {
                let item = queryArr[i];
                let curItem = item.split("=");
                if (curItem[0] === key) {
                    result = curItem[1];
                }
            }
        }
        return result;
    },
    printInfo(...info) {
        if (this.option.isConsoleLog) {
            console.log(`[${this.option.preFix}]==>`, ...info);
        }
    }
}

let createPath = function (url) {
    return new Path(url);
}

export default createPath;